package clientcore;
use IO::Socket::INET;
sub new {
    my ($class) = @_;
    return bless( {},$class);
}
# sub uri {
#     my ($self,$uri) = @_;
#     $self->{"uri"} = $uri;
# }
sub proxy {
    my ($self,$proxy) = @_;
    my($ip,$port) = split(":",$proxy,2);
    $self->{"proxy_ip"} = $ip;
    $self->{"proxy_port"} = $port;
}
sub AUTOLOAD {
    my ($self) = shift;
    my($_pck,$func_name)=split("::",$AUTOLOAD,2);
    if ($func_name eq "DESTROY") {
        return ;
    }
    print("from autoload:\$func_name is $func_name\n");
    $remote_host = $$self{"proxy_ip"};
    print("from autoload:\$proxy_ip is $remote_host\n");
    $remote_port = $$self{"proxy_port"};
    print("from autoload:\$proxy_port is $remote_port\n");
    $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
        PeerPort  => $remote_port,
        Proto => "tcp",
        Type => SOCK_STREAM)
        or die "Couldn't connect to $remote_host:$remote_port: $!\n";
    print $socket "$func_name\n";
    my @params  = @_;
    foreach my $param (@params){
        # chomp $param;
        # $param=~s/^\s*//;
        # $param=~s/\s*$//;
        # next if ($param eq "");
        print $socket $param;
        if (not ($param =~ /\n$/)) {
            print $socket "\n";
        }

    }
    print $socket "\r\n";
    @result = <$socket>;
    # print("\@result is @result\n");
    close($socket);
    return @result;
}
sub DESTORY {
    my ($self) = @_;

}

1;